*Stata code for "Just Right"

*Set working directory
cd "/Users/keithpreble/Library/CloudStorage/Dropbox/Replication Files for FPA/"

*Set environment - install packages if not loaded
clear all
*ssc install brewscheme
set scheme plotplainblind

*Load data set
use "goldilocks.dta", clear

*REGRESSION MODELS for Table 4a and 4b
*Code also include the data used to create Tables 1-3, too.
*Also, the code for the figures is here, too. 
*I created separate .do files for each of the figures, too.

******* MODEL 1: Median ****************
eststo M1: logit allbuster_median lagts3p lnlaggdpp c.lnlaggdpt##c.lnlaggdpt lagtradeopenp i.DefPactPT i.sanct_sev idealpointdistance duration arcsin_min nobust_median nobustsq_median nobustcb_mean if P_Sender !=1, robust

*Data that comes from this command produces the # of incidents of sanctions busting 
*and is added to Table 3 & Table 4a:
tab allbuster_median if e(sample)

******* MODEL 2: Mean ****************
eststo M2: logit allbuster_mean lagts3p lnlaggdpp c.lnlaggdpt##c.lnlaggdpt lagtradeopenp i.DefPactPT i.sanct_sev idealpointdistance duration arcsin_min nobust_mean nobustsq_mean nobustcb_mean if P_Sender !=1, robust

*Data that comes from this command produces the # of incidents of sanctions busting 
*and is added to Table 3 & Table 4a:
tab allbuster_mean if e(sample)

*Not necessary for the paper but can be run to see how the marginal effects change as DV coding shifts:
*margins, at(lnlaggdpt=(11.65844(0.5)23.14414))
*marginsplot

******* MODEL 3: 1 Percent ****************
*1 percent - this threshold serves as the "baseline" for the paper for all the figures and tables
*All figures and tables 1 and 2 are derived from this Regression Model unless noted otherwise

eststo M3a: logit allbuster_1pct lagts3p lnlaggdpp c.lnlaggdpt##c.lnlaggdpt lagtradeopenp i.DefPactPT i.sanct_sev idealpointdistance duration arcsin_min nobust_1pct nobustsq_1pct nobustcb_1pct if P_Sender !=1, robust

*Data that comes from this command produces the # of incidents of sanctions busting 
*and is added Table 4a; the results of this command are communicated solely in the text:
tab allbuster_1pct if e(sample)

*This code is used to create Figure 1:
graph bar (sum) allbuster_1pct if e(sample), over(target_bust, relabel(1 `""Smallest" "($145m-$973m)""' ///
	2 `""Small" "($973m-$6.42b)""'  ///
	3 `""Medium" "($6.42b-$282b)""'  ///
	4 `""Large" "($282b-$1.87t)""'  ///
	5 `""Largest" "($1.87t-$11.26t)""')) ///
    blabel(bar, size(small)) title("Sanctions Busting Events Across Target's Economic Size") ///
	ytitle("Sanctions Busting Events") b1title("Target's Economic Size")

*This code is used to create Table 1:
table targetname if e(sample), stat(mean nobust_1pct)
*copy the data to Excel, sort and create a Table for Word

*This code is used to create Table 2:
table targetname if e(sample), stat(sum allbuster_1pct)
*copy the data to Excel, sort and create a Table for Word

*Figure 3
margins, at(lnlaggdpt=(11.65844(0.5)23.14414))
marginsplot, recastci(rarea) recast(line) /// 
	ciopt(color(%20)) plotregion(margin(none)) xlabel(,labels angle(45)) ///
	title("Probability of Sanctions Busting Across Target's Economic Size") ///
	xtitle("Economic Size, Target (ln GDP)") ///
	ytitle("Probability of Sanctions Busting") ///
	ylabel(0.05(0.01).1) xlabel(,format(%9.2f)) 
*The red dots are placed on the small-, medium-, and larger-sized economies by hand

*Parsimonious Model is run to create Figure 4:
*First run the parsimonious logit:
eststo M3b: logit allbuster_1pct lagts3p lnlaggdpp c.lnlaggdpt##c.lnlaggdpt lagtradeopenp nobust_1pct nobustsq_1pct nobustcb_1pct if P_Sender !=1, robust

*Generate Figure 4
margins, at(lnlaggdpt=(11.65844(0.5)23.14414))
marginsplot, recastci(rarea) recast(line) /// 
	ciopt(color(%20)) plotregion(margin(none)) xlabel(,labels angle(45)) ///
	title("Probability of Sanctions Busting Across Target's Size Using Parsimonious Model")	   ///
	xtitle("Economic Size, Target (ln GDP)") ///
	ytitle("Probability of Sanctions Busting") ///
	ylabel(0.0(0.01).07) xlabel(,format(%9.2f)) ///
	xline(15.67) xline(19.46)
*Add the <- medium-sized economies -> label between the xlines manually

******* MODEL 4: 1 Standard Deviation ****************

*1 standard deviation
eststo M4: logit allbuster_1sd lagts3p lnlaggdpp c.lnlaggdpt##c.lnlaggdpt lagtradeopenp i.DefPactPT i.sanct_sev idealpointdistance duration arcsin_min nobust_1sd nobustsq_1sd nobustcb_1sd if P_Sender !=1, robust

*Data that comes from this command produces the # of incidents of sanctions busting 
*and is added to Table 3 & Table 4a:
tab allbuster_1sd if e(sample)

******* MODEL 5: 5 Percent ****************
*5% threshold (Early, Early and Spice) 
eststo M5: logit allbuster lagts3p lnlaggdpp c.lnlaggdpt##c.lnlaggdpt lagtradeopenp i.DefPactPT i.sanct_sev idealpointdistance duration arcsin_min nobust nobustsq nobustcb if P_Sender !=1, robust

*Data that comes from this command produces the # of incidents of sanctions busting 
*and is added to Table 3 & Table 4b:
tab allbuster if e(sample)

******* MODEL 6: 2 standard deviations ****************
*2 standard deviations
eststo M6: logit allbuster_2sd lagts3p lnlaggdpp c.lnlaggdpt##c.lnlaggdpt lagtradeopenp i.DefPactPT i.sanct_sev idealpointdistance duration arcsin_min nobust_2sd nobustsq_2sd nobustcb_2sd if P_Sender !=1, robust

*Data that comes from this command produces the # of incidents of sanctions busting 
*and is added to Table 3 & Table 4b:
tab allbuster_2sd if e(sample)

******* MODEL 7: US Sanctions Only Use 1% Threshold ****************
*US Sanctions Only using 1pct Threshold
eststo M7: logit allbuster_1pct lagts3p lnlaggdpp c.lnlaggdpt##c.lnlaggdpt lagtradeopenp i.DefPactPT i.sanct_sev idealpointdistance duration arcsin_min sender_tradeshare nobust_1pct nobustsq_1pct nobustcb_1pct if P_Sender !=1 & US_Sanctions==1, robust

*Data that comes from this command produces the # of incidents of sanctions busting and is added to Table 4b:
tab allbuster_1pct if e(sample)

***REGRESSION TABLES
***Regression Tables in the paper refer to Tables 4a and 4b
***Some minor edits by hand may be needed for labels and other minor adjustments

*Create Table 4a for screen viewing:
esttab M1 M2 M3a M4, se scalars(ll) aic bic pr2 label compress replace

*Creates Table 4a for export:
esttab M1 M2 M3a M4 using "table_new_rr1.rtf", se scalars(ll) aic bic pr2 label compress replace

*Creates Table 4b on the screen:
esttab M5 M6 M7, se scalars(ll) aic bic pr2 label compress replace

*Exports Table 4b for export:
esttab M5 M6 M7 using "table_new_rr2.rtf", se scalars(ll) aic bic pr2 label compress replace


**TO CREATE FIGURE 2, FOLLOW THESE INSTRUCTIONS**
*Load Data Set
use sanctions_events.dta, clear

*Set environment
set scheme plotplainblind

*Run Bar Graph
graph bar (count) caseid, over(target_gdp_graph, relabel(1 "Smallest-sized" ///
	2 "Small-sized" ///
	3 "Medium-sized" ///
	4 "Large-sized" ///
	5 "Largest-sized")) ///
	asyvars over(year, label(ticks tlcolor(black) angle(45) labsize(vsmall))) /// 
	legend(position(6) cols(5)) stack title("Economic Sanctions in Force by Economic Size (1962-2011)") ///
	ytitle("Economic Sanctions in Force") 
	

	
	

